// src/stores/userStore.js
import { ref } from 'vue';
import { defineStore } from 'pinia';
import { getMe } from '@/api/userApi';

export const useUserStore = defineStore('user', () => {
    // 定义用户信息状态
    const profile = ref({
        id: null,
        username: '',
        description: '',
        email: '',
        fullName: '',
        gender: '',
        createdAt: null,
        updatedAt: null,
        phoneNumber: '',
        address: '',
        dateOfBirth: null,
        profilePicture: '',
        isAdmin: false,
        likeCount: 0,
        articleCount: 0,
        questionCount: 0,
        answerCount: 0,
        unreadLikeCount: 0,
        unreadCommentCount: 0,
        followerCount: 0,
        followingCount: 0
    });

    const getProfile = () => {
        getMe().then(res => {
            profile.value = res.data
            console.log("获取用户信息成功: ", profile.value)
        }).catch(err => {
            console.log("获取用户信息失败: ", err)
        })
    }

    

    

    return { profile, getProfile };
}, {
    // 启用持久化功能
    persist: true
});
